package com.ruoyi.web.controller.talentServerController;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.core.domain.entity.SysRole;
import com.ruoyi.common.utils.SecurityUtils;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.TalChangeApply;
import com.ruoyi.system.service.ITalChangeApplyService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 人才变动申请Controller
 *
 * @author zhusq
 * @date 2023-04-30
 */
@RestController
@RequestMapping("/system/apply")
public class TalChangeApplyController extends BaseController
{
    @Autowired
    private ITalChangeApplyService talChangeApplyService;

    /**
     * 查询人才变动申请列表
     */
    @PreAuthorize("@ss.hasPermi('system:apply:list')")
    @GetMapping("/list")
    public TableDataInfo list(TalChangeApply talChangeApply)
    {
        startPage();
        /**数据权限*/
        List<SysRole> roles = SecurityUtils.getLoginUser().getUser().getRoles();
        for (SysRole role : roles) {
            if (role.getRoleKey().equals("common")) {
                talChangeApply.setUserId(SecurityUtils.getUserId());
            }
        }

        List<TalChangeApply> list = talChangeApplyService.selectTalChangeApplyList(talChangeApply);
        return getDataTable(list);
    }

    /**
     * 导出人才变动申请列表
     */
    @PreAuthorize("@ss.hasPermi('system:apply:export')")
    @Log(title = "人才变动申请", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TalChangeApply talChangeApply)
    {
        List<TalChangeApply> list = talChangeApplyService.selectTalChangeApplyList(talChangeApply);
        ExcelUtil<TalChangeApply> util = new ExcelUtil<TalChangeApply>(TalChangeApply.class);
        util.exportExcel(response, list, "人才变动申请数据");
    }

    /**
     * 获取人才变动申请详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:apply:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(talChangeApplyService.selectTalChangeApplyById(id));
    }

    /**
     * 新增人才变动申请
     */
    @PreAuthorize("@ss.hasPermi('system:apply:add')")
    @Log(title = "人才变动申请", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TalChangeApply talChangeApply)
    {
        return toAjax(talChangeApplyService.insertTalChangeApply(talChangeApply));
    }

    /**
     * 修改人才变动申请
     */
    @PreAuthorize("@ss.hasPermi('system:apply:edit')")
    @Log(title = "人才变动申请", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TalChangeApply talChangeApply)
    {
        return toAjax(talChangeApplyService.updateTalChangeApply(talChangeApply));
    }

    /**
     * 删除人才变动申请
     */
    @PreAuthorize("@ss.hasPermi('system:apply:remove')")
    @Log(title = "人才变动申请", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(talChangeApplyService.deleteTalChangeApplyByIds(ids));
    }

    /**管理员以及工作人员审核*/
    @GetMapping("/applyChange")
    public AjaxResult applyChange(@RequestParam("changeId") Long changeId ,@RequestParam("state") Integer state){
        talChangeApplyService.applyChange(changeId,state) ;
        return success() ;
    }

}
